package com.ruoyi.student_club.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.student_club.domain.ClubRecommend;
import com.ruoyi.student_club.mapper.ClubMemberMapper;
import com.ruoyi.student_club.mapper.ClubRecommendMapper;
import com.ruoyi.student_club.service.IClubRecommendService;
import com.ruoyi.student_club.vo.app.ClubRecommendVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 首页社团推荐Service业务层处理
 * 
 * @author 无尤
 * @date 2022-02-11
 */
@Service
public class ClubRecommendServiceImpl extends ServiceImpl<ClubRecommendMapper, ClubRecommend> implements IClubRecommendService{

    @Resource
    private ClubRecommendMapper clubRecommendMapper;

    @Resource
    private ClubMemberMapper memberMapper;

    @Override
    public List<ClubRecommendVo> getClubRecommend() {
        List<ClubRecommendVo> clubRecommendList = clubRecommendMapper.getClubRecommend();
        if (clubRecommendList.size() == 0){
            throw new RuntimeException("请先添加社团推荐");
        }
        //获取社团人数
        for (ClubRecommendVo vo : clubRecommendList) {
            int num = memberMapper.getPeople(vo.getClubId());
            vo.setPeople(num);
        }
        return clubRecommendList;
    }

}
